/*
* @Author: dengjiayao
* @Date:   2018-03-21 10:11:44
* @Last Modified by:   dengjiayao
* @Last Modified time: 2018-03-21 16:57:00
*/
import Pages from '../../component/pages/pages.vue'

import { showMsg, getSubaccountList } from '../../vuex/action'

export default {
  name: 'child-account-list',
  components: {
    'vue-pages': Pages
  },
  data() {
    return {
      list: [],
      pages: {
        start: 0,
        totalPages: 0,
        limit: 20
      }
    }
  },
  vuex: {
    getters: {
      fresh: state => state.hkListNeedFresh
    },
    actions: {
      xShowMsg: showMsg,
      xGetList: getSubaccountList
    }
  },
  created() {
    this.getList({})
  },
  methods: {
    getList({ start = this.pages.start, limit = this.pages.limit }) {
      this.xGetList({ start, limit })
        .then(ret => {
          let result = ret.data.result
          this.list = JSON.parse(result.list)
          this.pages.totalPages = Math.ceil(result.count / limit)
        })
        .catch(res => {
          this.xShowMsg({
            type: 'danger',
            content: res.error_msg
          })
        })
    }
  },
  watch: {
    fresh(val) {
      if (val) {
        this.getList({ start: 0 })
      }
    }
  }
}
